/// @tags: AutoMaton
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

namespace BlueQuantum {

int const N = 2e3 + 5;

char a[N], b[N];
bool vis[N << 1][N << 1];

struct AutoMaton {
  int root, tot, lst;
  int len[N << 1], ch[N << 1][26], link[N << 1], pre[30];

  inline void insert(int c) {
    int pos = lst, cur = lst = ++tot;
    len[cur] = len[pos] + 1;
    while (pos && !ch[pos][c]) ch[pos][c] = cur, pos = link[pos];
    if (!pos) return void(link[cur] = 1);
    int q = ch[pos][c];
    if (len[q] == len[pos] + 1) return void(link[cur] = q);
    int clone = ++tot;
    memcpy(ch[clone], ch[q], sizeof(ch[q]));
    len[clone] = len[pos] + 1, link[clone] = link[q], link[cur] = link[q] = clone;
    while (ch[pos][c] == q) ch[pos][c] = clone, pos = link[pos];
  }

  inline void buildSAM(char *const s) {
    tot = lst = root = 1;
    memset(link, 0, sizeof(link));
    memset(ch, 0, sizeof(ch));
    memset(len, 0, sizeof(len));
    int n = strlen(s);
    for (int i = 0; i < n; ++i) insert(s[i] - 'a');
  }

  inline void buildSeqAM(char *const s) {
    memset(ch, 0, sizeof(ch));
    memset(pre, 0, sizeof(pre));
    int n = strlen(s);
    root = n + 1;
    for (int i = n; i; --i) {
      for (int j = 0; j < 26; ++j) ch[i][j] = pre[j];
      pre[s[i - 1] - 'a'] = i;
    }
    for (int i = 0; i < 26; ++i) ch[root][i] = pre[i];
  }
} A, B;

struct Node {
  int a, b, len;
};

inline int query() {
  memset(vis, 0, sizeof(vis));
  queue<Node> q;
  q.push((Node){A.root, B.root, 0});
  vis[A.root][B.root] = true;
  while (!q.empty()) {
    Node u = q.front();
    q.pop();
    for (int i = 0; i < 26; ++i) {
      int a = A.ch[u.a][i], b = B.ch[u.b][i];
      if (!vis[a][b]) {
        if (a && !b) return u.len + 1;
        vis[a][b] = true;
        q.push((Node){a, b, u.len + 1});
      }
    }
  }
  return -1;
}

inline int main() {
  cin >> a >> b;
  A.buildSAM(a), B.buildSAM(b);
  cout << query() << '\n';
  A.buildSAM(a), B.buildSeqAM(b);
  cout << query() << '\n';
  A.buildSeqAM(a), B.buildSAM(b);
  cout << query() << '\n';
  A.buildSeqAM(a), B.buildSeqAM(b);
  cout << query() << '\n';
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4112 [HEOI2015] 最短不公共子串.in", "r", stdin);
  freopen("P4112 [HEOI2015] 最短不公共子串.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
